/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.vnf.bc;

import edu.upn.sigemfi.vnf.be.Giro;
import edu.upn.sigemfi.vnf.be.TransaccionNoFinanciera;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Programador
 */
public class TransaccionNoFinancieraDelegate {

    private TransaccionNoFinancieraFacadeLocal local;
    private TransaccionNoFinanciera giro;
    
     public TransaccionNoFinancieraDelegate(){
        local = lookupTransaccionNoFinancieraFacade();
    }

     public void crear(TransaccionNoFinanciera transaccionNoFinanciera) throws Exception{
         try {
             local.create(transaccionNoFinanciera);
         } catch (Exception e) {
             local = lookupTransaccionNoFinancieraFacade();
             throw new Exception("Crear Transaccion No Financiera" + e.getMessage());
         }

     }

     public void crearTransaccionNFGiro(Giro giro) throws Exception{
         try {
             local.create(giro);
         } catch (Exception e) {
             local = lookupTransaccionNoFinancieraFacade();
             throw new Exception("Crear Transaccion No Financiera Tipo Giro" + e.getMessage());
         }

     }

     public void editar(TransaccionNoFinanciera transaccionNoFinanciera) throws Exception{
         try {
             local.edit(transaccionNoFinanciera);
         } catch (Exception e) {
             local = lookupTransaccionNoFinancieraFacade();
             throw new Exception("Editar Transaccion No Financiera" + e.getMessage());
         }

     }

     public void eliminar(TransaccionNoFinanciera transaccionNoFinanciera) throws Exception{
         try {
             local.remove(transaccionNoFinanciera);
         } catch (Exception e) {
             local = lookupTransaccionNoFinancieraFacade();
             throw new Exception("Eliminar Transaccion No Financiera" + e.getMessage());
         }

     }

    private TransaccionNoFinancieraFacadeLocal lookupTransaccionNoFinancieraFacade() {
        try {
            Context c = new InitialContext();
            return (TransaccionNoFinancieraFacadeLocal) c.lookup("java:comp/env/TransaccionNoFinancieraFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}
